
from PIL import Image

from ai_mode.yolo import YOLO

yolo = YOLO()


# s = "C:\\Users\\72752\\PycharmProjects\\djangoProject\\img\\"
def predict(filename):
    file_header = "D:\\PycharmProjects\\djangoProject\\static\\uploads\\"
    img = file_header + filename
    try:
        image = Image.open(img)
    except:
        print('Open Error! Try again!')
    else:
        r_image = yolo.detect_image(image)
        # r_image.show()
        try:
            r_image.save(img)
        except:
            print("Save Wrong!")



# # img = input('Input image filename:')
# img = "D:\\yxc\\Study\\PycharmProjects\\djangoProject\\VOCdevkit\\VOC2007\\JPEGImages\\rice_0.jpg"
# # s = "D:\\yxc\\Study\\PycharmProjects\\djangoProject\\img"
# try:
#     image = Image.open(img)
# except:
#     print('Open Error! Try again!')
# else:
#     r_image = yolo.detect_image(image)
#     r_image.show()
#     # img.save('pred/pred_' + img)

